package com.example.hongyu.avtt.ui.adapter;

import android.content.Context;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.blankj.utilcode.util.StringUtils;
import com.bumptech.glide.Glide;
import com.example.hongyu.avtt.R;
import com.example.hongyu.avtt.model.Vedio;
import com.example.hongyu.avtt.ui.base.BaseAdapter;
import com.example.hongyu.avtt.ui.base.BaseViewHolder;
import com.example.hongyu.avtt.util.TransformationUtils;

import java.util.List;

import butterknife.BindView;

public class VedioListAdapter extends BaseAdapter<Vedio, VedioListAdapter.ViewHolder> {


    public VedioListAdapter(Context context, List<Vedio> list) {
        super(context, list);
    }

    @Override
    public int getItemView() {
        return R.layout.vedio_list_item_view;
    }

    @Override
    protected ViewHolder getViewHolder(View itemView) {
        return new ViewHolder(itemView);
    }

    @Override
    public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
        super.onBindViewHolder(holder, position);

        Vedio vedio= mList.get(position);
        holder.itemDuration.setText(StringUtils.isEmpty(vedio.getDuration())?"":vedio.getDuration());
        holder.name.setText((position+1)+"*"+ (StringUtils.isEmpty(vedio.getTitle())?"":"["+vedio.getTitle()+"]")+vedio.getName());
        holder.playTimes.setText(""+vedio.getPlayTimes());
        holder.hideTimes.setText(""+vedio.getLikeTimes());
        holder.downLoadTimes.setText(""+vedio.getDownLoadTimes());
        Glide.with(mContext).load(vedio.getImage()).asBitmap()
                .placeholder(R.mipmap.no_image).into(new TransformationUtils(holder.icon));

    }
    static class ViewHolder extends BaseViewHolder {

        @BindView(R.id.item_name)
        TextView name;
        @BindView(R.id.item_play_times)
        TextView playTimes;
        @BindView(R.id.item_download_times)
        TextView downLoadTimes;
        @BindView(R.id.item_hide_times)
        TextView hideTimes;
        @BindView(R.id.item_icon)
        ImageView icon;

        @BindView(R.id.item_duration)
        TextView itemDuration;


        public ViewHolder(View itemView) {
            super(itemView);
        }
    }
}
